﻿/**  版本信息模板在安装目录下，可自行修改。
* FA_CHECKPLAN.cs
*
* 功 能： N/A
* 类 名： FA_CHECKPLAN
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013/10/14 11:17:57   N/A    初版
*
* Copyright (c) 2012 TKFA Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：TKFA　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using System.Collections.Generic;
using TKFA.IDAL;
using Maticsoft.DBUtility;//Please add references
namespace TKFA.OracleDAL
{
	/// <summary>
	/// 数据访问类:FA_CHECKPLAN
	/// </summary>
	public partial class FA_CHECKPLAN:IFA_CHECKPLAN
	{
		public FA_CHECKPLAN()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(TKFA.Model.FA_CHECKPLAN model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into FA_CHECKPLAN(");
			strSql.Append("SCORPCODE,SCHECKPLANID,SPERIOD,SCHECKPLANNAME,SCONTENTSCODE,SCP_MCARDCODE,SCP_ASSETSCODE,SCP_USER,SCP_STARTTIME,SCP_ENDTIME,SCP_MAKER)");
			strSql.Append(" values (");
			strSql.Append(":SCORPCODE,:SCHECKPLANID,:SPERIOD,:SCHECKPLANNAME,:SCONTENTSCODE,:SCP_MCARDCODE,:SCP_ASSETSCODE,:SCP_USER,:SCP_STARTTIME,:SCP_ENDTIME,:SCP_MAKER)");
			OracleParameter[] parameters = {
					new OracleParameter(":SCORPCODE", OracleType.VarChar,20),
					new OracleParameter(":SCHECKPLANID", OracleType.VarChar,20),
					new OracleParameter(":SPERIOD", OracleType.VarChar,20),
					new OracleParameter(":SCHECKPLANNAME", OracleType.VarChar,20),
					new OracleParameter(":SCONTENTSCODE", OracleType.VarChar,20),
					new OracleParameter(":SCP_MCARDCODE", OracleType.VarChar,20),
					new OracleParameter(":SCP_ASSETSCODE", OracleType.VarChar,20),
					new OracleParameter(":SCP_USER", OracleType.VarChar,20),
					new OracleParameter(":SCP_STARTTIME", OracleType.VarChar,20),
					new OracleParameter(":SCP_ENDTIME", OracleType.VarChar,20),
					new OracleParameter(":SCP_MAKER", OracleType.VarChar,20)};
			parameters[0].Value = model.SCORPCODE;
			parameters[1].Value = model.SCHECKPLANID;
			parameters[2].Value = model.SPERIOD;
			parameters[3].Value = model.SCHECKPLANNAME;
			parameters[4].Value = model.SCONTENTSCODE;
			parameters[5].Value = model.SCP_MCARDCODE;
			parameters[6].Value = model.SCP_ASSETSCODE;
			parameters[7].Value = model.SCP_USER;
			parameters[8].Value = model.SCP_STARTTIME;
			parameters[9].Value = model.SCP_ENDTIME;
			parameters[10].Value = model.SCP_MAKER;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(TKFA.Model.FA_CHECKPLAN model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update FA_CHECKPLAN set ");
			strSql.Append("SCORPCODE=:SCORPCODE,");
			strSql.Append("SCHECKPLANID=:SCHECKPLANID,");
			strSql.Append("SPERIOD=:SPERIOD,");
			strSql.Append("SCHECKPLANNAME=:SCHECKPLANNAME,");
			strSql.Append("SCONTENTSCODE=:SCONTENTSCODE,");
			strSql.Append("SCP_MCARDCODE=:SCP_MCARDCODE,");
			strSql.Append("SCP_ASSETSCODE=:SCP_ASSETSCODE,");
			strSql.Append("SCP_USER=:SCP_USER,");
            strSql.Append("STATUS=:STATUS,");
			strSql.Append("SCP_STARTTIME=:SCP_STARTTIME,");
			strSql.Append("SCP_ENDTIME=:SCP_ENDTIME,");
			strSql.Append("SCP_MAKER=:SCP_MAKER");
			strSql.Append(" where ");
			OracleParameter[] parameters = {
					new OracleParameter(":SCORPCODE", OracleType.VarChar,20),
					new OracleParameter(":SCHECKPLANID", OracleType.VarChar,20),
					new OracleParameter(":SPERIOD", OracleType.VarChar,20),
					new OracleParameter(":SCHECKPLANNAME", OracleType.VarChar,20),
					new OracleParameter(":SCONTENTSCODE", OracleType.VarChar,20),
					new OracleParameter(":SCP_MCARDCODE", OracleType.VarChar,20),
					new OracleParameter(":SCP_ASSETSCODE", OracleType.VarChar,20),
					new OracleParameter(":SCP_USER", OracleType.VarChar,20),
					new OracleParameter(":SCP_STARTTIME", OracleType.VarChar,20),
					new OracleParameter(":SCP_ENDTIME", OracleType.VarChar,20),
                    new OracleParameter(":STATUS", OracleType.VarChar,20),
					new OracleParameter(":SCP_MAKER", OracleType.VarChar,20)};
			parameters[0].Value = model.SCORPCODE;
			parameters[1].Value = model.SCHECKPLANID;
			parameters[2].Value = model.SPERIOD;
			parameters[3].Value = model.SCHECKPLANNAME;
			parameters[4].Value = model.SCONTENTSCODE;
			parameters[5].Value = model.SCP_MCARDCODE;
			parameters[6].Value = model.SCP_ASSETSCODE;
			parameters[7].Value = model.SCP_USER;
			parameters[8].Value = model.SCP_STARTTIME;
			parameters[9].Value = model.SCP_ENDTIME;
            parameters[10].Value = model.STATUS;
			parameters[11].Value = model.SCP_MAKER;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

        public bool UpdateTatus(TKFA.Model.FA_CHECKPLAN model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update FA_CHECKPLAN set ");
            strSql.Append("STATUS=:STATUS");
            strSql.Append(" where ");
            strSql.Append(" SCORPCODE=:SCORPCODE");
            strSql.Append(" AND SCHECKPLANID=:SCHECKPLANID");
            strSql.Append(" AND SPERIOD=:SPERIOD");
            strSql.Append(" AND SCHECKPLANNAME=:SCHECKPLANNAME");
            strSql.Append(" AND SCONTENTSCODE=:SCONTENTSCODE");
            strSql.Append(" AND SCP_MCARDCODE=:SCP_MCARDCODE");
            strSql.Append(" AND SCP_ASSETSCODE=:SCP_ASSETSCODE");
            strSql.Append(" AND SCP_USER=:SCP_USER");
            strSql.Append(" AND SCP_STARTTIME=:SCP_STARTTIME");
            strSql.Append(" AND SCP_ENDTIME=:SCP_ENDTIME");
            strSql.Append(" AND SCP_MAKER=:SCP_MAKER");
            OracleParameter[] parameters = {
					new OracleParameter(":SCORPCODE", OracleType.VarChar,20),
					new OracleParameter(":SCHECKPLANID", OracleType.VarChar,20),
					new OracleParameter(":SPERIOD", OracleType.VarChar,20),
					new OracleParameter(":SCHECKPLANNAME", OracleType.VarChar,20),
					new OracleParameter(":SCONTENTSCODE", OracleType.VarChar,20),
					new OracleParameter(":SCP_MCARDCODE", OracleType.VarChar,20),
					new OracleParameter(":SCP_ASSETSCODE", OracleType.VarChar,20),
					new OracleParameter(":SCP_USER", OracleType.VarChar,20),
					new OracleParameter(":SCP_STARTTIME", OracleType.VarChar,20),
					new OracleParameter(":SCP_ENDTIME", OracleType.VarChar,20),
                    new OracleParameter(":STATUS", OracleType.VarChar,20),
					new OracleParameter(":SCP_MAKER", OracleType.VarChar,20)};
            parameters[0].Value = model.SCORPCODE;
            parameters[1].Value = model.SCHECKPLANID;
            parameters[2].Value = model.SPERIOD;
            parameters[3].Value = model.SCHECKPLANNAME;
            parameters[4].Value = model.SCONTENTSCODE;
            parameters[5].Value = model.SCP_MCARDCODE;
            parameters[6].Value = model.SCP_ASSETSCODE;
            parameters[7].Value = model.SCP_USER;
            parameters[8].Value = model.SCP_STARTTIME;
            parameters[9].Value = model.SCP_ENDTIME;
            parameters[10].Value = model.STATUS;
            parameters[11].Value = model.SCP_MAKER;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from FA_CHECKPLAN ");
			strSql.Append(" where ");
			OracleParameter[] parameters = {
			};

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


        /// <summary>
        /// 获取盘点计划列表
        /// </summary>
        /// <param name="wherestr"></param>
        /// <returns></returns>
        public DataTable GetCheckPlan()
        {
            TKFA.Model.FA_CHECKPLAN model = new TKFA.Model.FA_CHECKPLAN();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select distinct SCORPCODE,SCHECKPLANID,SPERIOD,SCHECKPLANNAME,SCP_USER, SCP_STARTTIME,SCP_ENDTIME,SCP_MAKER from FA_CHECKPLAN ");

            DataSet ds = DbHelperOra.Query(strSql.ToString());
            if (ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            else
            {
                return null;
            }
        }

        public DataTable GetCheckPlanALlValue()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from FA_CHECKPLAN ");
            DataSet ds = DbHelperOra.Query(strSql.ToString());
            if (ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            else
            {
                return null;
            }
        }

        public DataTable GetCheckPlanALlValue(string checkplanid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from FA_CHECKPLAN where SCHECKPLANID=:checkplanid ");
            OracleParameter[] parameters = {
					new OracleParameter(":checkplanid", OracleType.VarChar,20)};
            parameters[0].Value =checkplanid;
            DataSet ds = DbHelperOra.Query(strSql.ToString(),parameters);
            if (ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            else
            {
                return null;
            }
        }


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public TKFA.Model.FA_CHECKPLAN GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SCORPCODE,SCHECKPLANID,SPERIOD,SCHECKPLANNAME,SCONTENTSCODE,SCP_MCARDCODE,SCP_ASSETSCODE,SCP_USER,SCP_STARTTIME,SCP_ENDTIME,SCP_MAKER from FA_CHECKPLAN ");
			strSql.Append(" where ");
			OracleParameter[] parameters = {
			};

			TKFA.Model.FA_CHECKPLAN model=new TKFA.Model.FA_CHECKPLAN();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public TKFA.Model.FA_CHECKPLAN DataRowToModel(DataRow row)
		{
			TKFA.Model.FA_CHECKPLAN model=new TKFA.Model.FA_CHECKPLAN();
			if (row != null)
			{
                DataColumnCollection dc = row.Table.Columns;
                if (dc.Contains("SCORPCODE") && row["SCORPCODE"] != null)
				{
					model.SCORPCODE=row["SCORPCODE"].ToString();
				}
                if (dc.Contains("SCHECKPLANID") && row["SCHECKPLANID"] != null)
				{
					model.SCHECKPLANID=row["SCHECKPLANID"].ToString();
				}
                if (dc.Contains("SPERIOD") && row["SPERIOD"] != null)
				{
					model.SPERIOD=row["SPERIOD"].ToString();
				}
                if (dc.Contains("SCHECKPLANNAME") && row["SCHECKPLANNAME"] != null)
				{
					model.SCHECKPLANNAME=row["SCHECKPLANNAME"].ToString();
				}
                if (dc.Contains("SCONTENTSCODE") && row["SCONTENTSCODE"] != null)
				{
					model.SCONTENTSCODE=row["SCONTENTSCODE"].ToString();
				}
                if (dc.Contains("SCP_MCARDCODE") && row["SCP_MCARDCODE"] != null)
				{
					model.SCP_MCARDCODE=row["SCP_MCARDCODE"].ToString();
				}
                if (dc.Contains("SCP_ASSETSCODE") && row["SCP_ASSETSCODE"] != null)
				{
					model.SCP_ASSETSCODE=row["SCP_ASSETSCODE"].ToString();
				}
                if (dc.Contains("SCP_USER") && row["SCP_USER"] != null)
				{
					model.SCP_USER=row["SCP_USER"].ToString();
				}
                if (dc.Contains("SCP_STARTTIME") && row["SCP_STARTTIME"] != null)
				{
					model.SCP_STARTTIME=row["SCP_STARTTIME"].ToString();
				}
                if (dc.Contains("SCP_ENDTIME") && row["SCP_ENDTIME"] != null)
				{
					model.SCP_ENDTIME=row["SCP_ENDTIME"].ToString();
				}
                if (dc.Contains("SCP_MAKER") && row["SCP_MAKER"] != null)
				{
					model.SCP_MAKER=row["SCP_MAKER"].ToString();
				}
                if (dc.Contains("STATUS") && row["STATUS"] != null)
                {
                    model.STATUS = row["STATUS"].ToString();
                }
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SCORPCODE,SCHECKPLANID,SPERIOD,SCHECKPLANNAME,SCONTENTSCODE,SCP_MCARDCODE,SCP_ASSETSCODE,SCP_USER,SCP_STARTTIME,SCP_ENDTIME,SCP_MAKER ");
			strSql.Append(" FROM FA_CHECKPLAN ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM FA_CHECKPLAN ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.SCONTENTSCODE desc");
			}
			strSql.Append(")AS Row, T.*  from FA_CHECKPLAN T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "FA_CHECKPLAN";
			parameters[1].Value = "SCONTENTSCODE";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

